<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Session;
class User extends  Controller
{
    public function admin_info()
    {  $name=Session::get("name");
       
       $res=Db::name('backstage')
       ->where("manger_name",'=',$name)
       ->find();
       $this->assign("res",$res);
        return $this->fetch('admin_info');
    }
    
    public  function  administrator()
    {
        
          //查询数据库
		 $res = Db::name('backstage')->paginate(3);
        $this->assign("data",$res);
        return $this->fetch('administrator');
       
    }
	public  function  updatapwd(){
	    $name=$_POST['name'];
	    $pwd=$_POST['pwd'];
	    $res=Db::table('backstage')
	    ->where('manger_name',$name)
	    ->update(['manger_pwd'=>$pwd]);
	    if(count($res)>0){
	        $raw_success = array( 'msg' => 'ok');
	        return json($raw_success);
	    }
	    else {
	        $raw_success = array( 'msg' => 'no');
	        return json($raw_success);
	    }
	    
	}
	public function updatauser(){
	    $name=$_POST['username'];
	    $tel=$_POST['tel'];
	    $email=$_POST['email'];
	    $userid=$_POST['userid'];
	    $res=Db::table('backstage')
	    ->where('manger_id',$userid)
	    ->update(['manger_name'=>$name,'manger_tel'=>$tel,'manger_email'=>$email]);
	    if(count($res)>0){
	        $raw_success = array( 'msg' => 'ok');
	        return json($raw_success);
	    }
	    else {
	        $raw_success = array( 'msg' => 'no');
	        return json($raw_success);
	    }
	    
	}
}

